require "ImguiWin/BaseImguiWindow"
require "UnityEngine.SystemInfo"

local P = NewClass(BaseImguiWindow, ClassFromFile(...));

local GUILayout = UnityEngine.GUILayout
local GUI = UnityEngine.GUI
local Screen = UnityEngine.Screen



local scrollPos = Vector2.zero

function P:OnGUI()
	GUIFun.Init()
	GUILayout.Box("", GUILayout.Height(Screen.height), GUILayout.Width(Screen.width))
	self:Show()
end

function P:Show()
	local space = 0
	GUILayout.BeginArea(self:GetFullScreenAreaRect())
	GUILayout.BeginVertical()

	scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUILayout.Width(Screen.width));
	GUILayout.BeginVertical()
	GUIFun.Label(VoiceManager.instance:ToString(), true, space)

	if GUIFun.Button("EnableSpeakerOn: "..tostring(self.enableSpeakerOnOutput), false, 0) then
		self.enableSpeakerOnOutput = VoiceManager.instance:EnableSpeakerOn(true)
	end

	if GUIFun.Button("EnableRoomSpeaker: "..tostring(self.enableRoomSpeakerOutput), false, 0) then
		self.enableRoomSpeakerOutput = VoiceManager.instance:EnableRoomSpeaker(true)
	end

	if GUIFun.Button("EnableRoomMic: "..tostring(self.enableRoomMicOutput), false, 0) then
		self.enableRoomMicOutput = VoiceManager.instance:EnableRoomMic(true)
	end
	
	if GUIFun.Button("TestMic: "..tostring(self.testMicOutput), false, 0) then
		self.testMicOutput = VoiceManager.instance:TestMic()
	end

	if GUIFun.Button("EnableMic: "..tostring(self.enableMicOutput), false, 0) then
		self.enableMicOutput = VoiceManager.instance:EnableMic(not VoiceManager.instance:isEnableMic())
	end

	if GUIFun.Button("EnableSpeaker: "..tostring(self.enableSpeakerOutput), false, 0) then
		self.enableSpeakerOutput = VoiceManager.instance:EnableSpeaker(not VoiceManager.instance:isEnableSpeaker())
	end

	GUILayout.BeginHorizontal()
	
	if not self.micVolume then
		self.micVolume = 0
	end

	local tempVolume = GUILayout.HorizontalSlider(self.micVolume, 0, 500, GUIFun.Width(1000))
	if self.micVolume ~= tempVolume then
		self.micVolume = tempVolume
		self.setMicVolumeOutput = VoiceManager.instance:SetMicVolume(self.micVolume)
	end

	if self.setMicVolumeOutput then
		GUIFun.Label("set mic volume result: "..tostring(self.setMicVolumeOutput), false, 0)
	end

	GUIFun.Label("mic level: "..tostring(VoiceManager.instance:GetMicLevel()), false, 0)

	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()

	GUILayout.BeginHorizontal()
	if not self.speakerVolume then
		self.speakerVolume = 0
	end

	local tempVolume = GUILayout.HorizontalSlider(self.speakerVolume, 0, 500, GUIFun.Width(1000))
	if self.speakerVolume ~= tempVolume then
		self.speakerVolume = tempVolume
		self.setSpeakerVolumeOutput = VoiceManager.instance:SetSpeakerVolume(self.speakerVolume)
	end

	if self.setSpeakerVolumeOutput then
		GUIFun.Label("set speaker volume result: "..tostring(self.setSpeakerVolumeOutput), false, 0)
	end

	GUIFun.Label("speaker level: "..tostring(VoiceManager.instance:GetSpeakerLevel()), false, 0)
	
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()


	-- GUILayout.BeginHorizontal()
	-- GUIFun.Label("speaker volume: "..tostring(VoiceManager.instance:GetSpeakerVolume()), false, 0)
	-- local volume = GUILayout.HorizontalSlider(VoiceManager.instance:GetSpeakerVolume(), 0, 500, GUIFun.Width(1000))
	-- VoiceManager.instance:SetSpeakerVolume(volume)
	-- GUILayout.FlexibleSpace()
	-- GUILayout.EndHorizontal()




	GUILayout.EndVertical()
	GUILayout.EndScrollView()

	GUILayout.BeginHorizontal()
	if GUILayout.Button("close", GUIFun.Height(100)) then
		self._funObj:Close()
	end
	GUILayout.EndHorizontal()

	GUILayout.EndVertical()
	GUILayout.EndArea()
end
